package cn.javaxc.mvcwork.modules.file;
import cn.javaxc.mvcwork.framework.beans.TFormBean;
import cn.javaxc.mvcwork.util.common.DatabaseUtils;
import java.sql.*;
import cn.javaxc.model.base.*;
import cn.javaxc.mvcwork.util.common.*;
import cn.javaxc.mvcwork.util.helper.FrameHelper;


public class FileDownloadLog extends TFormBean {

  private int id = -1;
  private Object itemId = -1;
  private double version = -1;
  private int userId = -1;
  private java.sql.Timestamp downloadDate = null;
  private int fileSize = 0;
  private java.sql.Timestamp entered = null;
  private java.sql.Timestamp modified = null;


  
  public java.sql.Timestamp getEntered() {
    return entered;
  }


  
  public void setEntered(java.sql.Timestamp tmp) {
    this.entered = tmp;
  }


  
  public void setEntered(String tmp) {
    this.entered = DatabaseUtils.parseTimestamp(tmp);
  }


  
  public java.sql.Timestamp getModified() {
    return modified;
  }


  
  public void setModified(java.sql.Timestamp tmp) {
    this.modified = tmp;
  }


  
  public void setModified(String tmp) {
    this.modified = DatabaseUtils.parseTimestamp(tmp);
  }



  
  public int getId() {
    return id;
  }


  
  public void setId(int tmp) {
    this.id = tmp;
  }


  
  public void setId(String tmp) {
    this.id = Integer.parseInt(tmp);
  }


  
  public FileDownloadLog() { }





  
  public void setItemId(Object tmp) {
    this.itemId = tmp;
  }



  
  public void setVersion(double tmp) {
    this.version = tmp;
  }


  
  public void setVersion(String tmp) {
    this.version = Double.parseDouble(tmp);
  }


  
  public void setUserId(int tmp) {
    this.userId = tmp;
  }


  
  public void setUserId(String tmp) {
    this.userId = Integer.parseInt(tmp);
  }


  
  public void setDownloadDate(java.sql.Timestamp tmp) {
    this.downloadDate = tmp;
  }


  
  public void setDownloadDate(String tmp) {
    this.downloadDate = DatabaseUtils.parseTimestamp(tmp);
  }


  
  public void setFileSize(int tmp) {
    this.fileSize = tmp;
  }


  
  public Object getItemId() {
    return itemId;
  }


  
  public double getVersion() {
    return version;
  }


  
  public int getUserId() {
    return userId;
  }


  
  public java.sql.Timestamp getDownloadDate() {
    return downloadDate;
  }


  
  public int getFileSize() {
    return fileSize;
  }





  
  public boolean updateCounter()  {
    if (StringUtils.isNullData(itemId) || version < 0) {
      return false;
    }
    //Record the raw number of downloads
	SQLMap pst = FrameHelper.getBaseSQL().createStatement();
    String sql = (
        "UPDATE ts_files " +
        "SET downloads = (downloads + 1) " +
        "WHERE item_id = ? ");
    pst.setObject(1, itemId);
    pst.execute(sql);
	pst = FrameHelper.getBaseSQL().createStatement();
    sql = (
        "UPDATE ts_files_version " +
        "SET downloads = (downloads + 1) " +
        "WHERE item_id = ? " +
        "AND version = ? ");
    pst.setObject(1, itemId);
    pst.setDouble(2, version);
    pst.execute(sql);
    return true;
  }
}
